<?php

// 审核项目
// PUT project.admin.audit

namespace app\api\resource\project\admin;
use think\Db;

class Audit
{
    // 方法
    public $_method = ['PUT'];
    // 前置
    public $_pre    = ['adminLogin'];
    // 描述
    public $_description = '审核项目';
    // 参数
    public $_param  = [
        'project_id' => '项目主键',
        'status'     => '审核状态,0-找回 1-删除',
    ];
    // 返回
    public $_return = [
        201 => '操作成功',
        422 => '项目主键必须|审核状态必须',
        500 => '服务器异常',
    ];

    public function run(&$request)
    {
        $projectId = $request->put('project_id/d',0);
        $status    = $request->put('status/d',-1);

        if (0 == $projectId) return [422,'项目主键必须'];
        if (-1 == $status)   return [422,'审核状态必须'];

        $data['delete_time'] = $status ? time() : 0;
        $num = Db::name('project')->where('id',$projectId)->update($data);

        return ($num >= 0) ? [ 201,[] ] : 500;
    }
}